package library

class BookService {
	boolean transactional = false
	def getStaticBook() {
		return new Book(author: "Anonymous",
                title: "Eggs", description: "yummy",
                isbn: "0000000000" , minGrade: 2, maxGrade: 6,
                language: "English", category: "fiction")
	}
	def getRandomBook() {
		def allBooks = library.Book.list()
		def randomBook = null
		if (allBooks.size() > 0) {
			def randomIdx = new Random().nextInt(allBooks.size())
			randomBook = allBooks[randomIdx]
		} else {
			randomBook = getStaticBook()
		}
		return randomBook
	}
}